import request from '@/router/axios';
import {baseUrl} from '@/config/env';


export const list = (data) => {
    return request({
            url: baseUrl + '/start/formEngine/form/page',
            method: 'get',
            data: data
        }
    )
}
export const add = (data) => {
    return request({
            url: baseUrl + '/start/formEngine/form/add',
            method: 'post',
            data: data
        }
    )
}

export const getById = (id) => {
    return request({
            url: baseUrl + '/start/formEngine/form/getById/' + id,
            method: 'get',
        }
    )
}

export const updateById = (id, data, index) => {
    return request({
            url: baseUrl + '/start/formEngine/form/updateById',
            method: 'put',
            data: data
        }
    )
}

export const deleteById = (id) => {
    return request({
            url: baseUrl + '/start/formEngine/form/deleteById/' + id,
            method: 'delete',
        }
    )
}

export const getByTableId = (tableId) => {
    return request({
            url: baseUrl + '/start/formEngine/form/getByTableId/' + tableId,
            method: 'get',
        }
    )
}
export const createMenu = (tableId, data) => {
    return request({
            url: baseUrl + '/start/formEngine/form/createMenu/' + tableId,
            method: 'get',
            params: data,
        }
    )
}
export const getTableOption = (tableId) => {
    return request({
            url: baseUrl + '/start/formEngine/form/getTableOption/' + tableId,
            method: 'get',
        }
    )
}


export const saveTableOption = (tableId, data) => {
    return request({
            url: baseUrl + '/sysFormConfig/saveTableOption/' + tableId,
            method: 'post',
            data: data,
        }
    )
}

export const synchronizationTable = (tableId) => {
    return request({
            url: `${baseUrl}/start/formEngine/form/synchronizationTable/${tableId}/` + 5,
            method: 'get',

        }
    )
}
export const getAllStorage = () => {
    return request({
            url: `${baseUrl}/start/formEngine/form/getAllStorage`,
            method: 'get',
        }
    )
}
export const saveOrUpdate = (data) => {
    if (data.id) {
        return updateById(data.id, data);
    }
    return add(data)
}
const formApi = {
    saveOrUpdate
}
export default formApi